package com.fancy.common.spi.proxy;

import java.net.Authenticator;
import java.net.PasswordAuthentication;

/**
 * 代理认证类
 * 
 * @author wlei   2013-4-13下午2:51:01
 * @version 1.0.0
 * @category 杭州广桥网络技术有限公司(商业先知)
 */
public class DefaultProxyAuthenticator extends Authenticator {

    private String user;
    private String password;
    private static DefaultProxyAuthenticator authenticator;

    public DefaultProxyAuthenticator(String user, String password) {
        this.user = user;
        this.password = password;
    }

    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(user, password.toCharArray());
    }

    public static Authenticator getInstance(String user, String password) {
        if (authenticator == null) {
            authenticator = new DefaultProxyAuthenticator(user, password);
        }
        return authenticator;
    }
}